﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

using ARCHFORME.Common;

using Castle.Windsor;
using Castle.Windsor.Installer;

using Sample.Host.Infrastructure;

namespace Sample.Host
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            BootstrapContainer();
        }

        private static void BootstrapContainer()
        {
            

            //container.Install(FromAssembly.InThisApplication(new CustomInstallerFactory()));
            //container.Install(FromAssembly.InThisApplication());

            IoC.Container.Install(FromAssembly.Named("ARCHFORME.Core"));
            IoC.Container.Install(FromAssembly.InThisApplication());

            var controllerFactory = new WindsorControllerFactory(IoC.Container.Kernel);
            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
        }
    }

    public class CustomInstallerFactory : InstallerFactory
    {
        public override IEnumerable<Type> Select(IEnumerable<Type> installerTypes)
        {
            return installerTypes.Reverse(); // just as an example
        }
    }
}